package com.xiaoy.exception;


/**
 * 异常处理
 * @author chentianyi
 *
 */
public class SystemException extends RuntimeException {

	private static final long serialVersionUID = 3583566093089790852L;

	
	private SystemException cause = this;
    public SystemException getCause() {
        return (cause==this ? null : cause);
    }
	
	
	private String key;
	private Object[] values;
	
//	private String errerMessage;
//	public void printStackTrace() {
//        printStackTrace(System.err);
//    }
//    public void printStackTrace(PrintStream s) {
//        synchronized (s) {
//            s.println(this);
//            StackTraceElement[] trace = getOurStackTrace();
//            for (int i=0; i < trace.length; i++)
//                s.println("\tat " + trace[i]);
//
//            Throwable ourCause = getCause();
//            if (ourCause != null)
//                ourCause.printStackTraceAsCause(s, trace);
//        }
//    	StackTraceElement[] trace = getStackTrace();
//        for (int i=0; i < trace.length; i++)
//            s.println("\tat " + trace[i]);
//
//        SystemException ourCause = getCause();
//        if (ourCause != null)
//            ourCause.printStackTraceAsCause(s, trace);
//    	
//    	getStackTrace();
//    }	
//    private void printStackTraceAsCause(PrintStream s,
//            StackTraceElement[] causedTrace)
//	{
//	// assert Thread.holdsLock(s);
//	
//	// Compute number of frames in common between this and caused
//	StackTraceElement[] trace = getOurStackTrace();
//	int m = trace.length-1, n = causedTrace.length-1;
//	while (m >= 0 && n >=0 && trace[m].equals(causedTrace[n])) {
//	m--; n--;
//	}
//	int framesInCommon = trace.length - 1 - m;
//	
//	s.println("Caused by: " + this);
//	for (int i=0; i <= m; i++)
//	s.println("\tat " + trace[i]);
//	if (framesInCommon != 0)
//	s.println("\t... " + framesInCommon + " more");
//	
//	// Recurse if we have a cause
//	Throwable ourCause = getCause();
//	if (ourCause != null)
//	ourCause.printStackTraceAsCause(s, trace);
//	}
//	public String getErrerMessage() {
//		
//		StackTraceElement[] trace = getStackTrace();
//		return errerMessage;
//	}

	public SystemException() {
		super();
	}
	
	public SystemException(String message) {
		super(message);
	}
	
	public SystemException(Throwable throwable) {
		super(throwable);
	}
	
	public SystemException(String message, Throwable throwable) {
		super(message, throwable);
	}
	
	public SystemException(String key,String message){
		super(message);
		this.key = key;
	}
	
	public SystemException(String key,String message,Throwable throwable){
		this(message,throwable);
		this.key = key;
	}
	
	public SystemException(String key,Object value,String message){
		super(message);
		this.key = key;
		this.values = new Object[]{value};
	}
	
	public SystemException(String key,Object[] values,String message){
		super(message);
		this.key = key;
		this.values = values;
	}
	public String getKey() {
		return key;
	}
	public Object[] getValues() {
		return values;
	}
}
